﻿using System.Collections.Specialized;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tigera.Network;
using Tigera.T_Definition;
using System.Configuration;


namespace Plugin.NetRiskMgr
{
    public partial class FormLogin : Form
    {
        public FormLogin()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
            if (MQClient.Instance.Debugmode == true)
            {
                this.Text += "测试模式";
                this.textBox1.Text = "test";
                this.textBox2.Text = "test";
            }
            
        }

        private void btn_Login_Click(object sender, EventArgs e)
        {
            if ( string.IsNullOrEmpty(this.textBox1.Text) || string.IsNullOrEmpty(this.textBox2.Text)  )
            {
                MessageBox.Show("请输入用户密码");
                return;
            }


            MQClient.Instance.MQConn = new MQConnection(Guid.NewGuid().ToString(), NetStateHandler.DefaultInstance);
            MQClient.Instance.MQConn.MessageReceived += new EventHandler<Tigera.LibCodeUtils.MessageEventArgs>(_conn_MessageReceived);
                    

        }

        void _conn_MessageReceived(object sender, Tigera.LibCodeUtils.MessageEventArgs e)
        {
            switch ((MessageID)e.Data.TypeID)
            {
                case MessageID.LogonResponse:
                    {
                        var res = e.Data.Cast<LogonResponse>();
                        if (res.Result == LogonResult.Succeed)
                        {
                            MessageBox.Show(this,"登录成功");
                            MQClient.Instance.Logined = true;
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                            
                        }
                        else
                        {
                            MessageBox.Show("登录失败");
                        }

                        break; ;

                    }
                default:
                    break;
            }
            
        }
        

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
            this.DialogResult = DialogResult.Cancel;
        }

     
       
    }
}
